(function () {
  var sampleCharacter = {
    combat: {
      physAtk: 125,
      magicAtk: 98,
      damagePower: 1.35,
      defense: 210,
      resist: 85
    },
    base: {
      vitality: 42,
      strength: 38,
      agility: 30,
      intelligence: 26,
      spirit: 22
    },
    tactical: {
      crit: 21,
      hit: 87,
      block: 14,
      dodge: 11
    },
    equips: {
      'head-ornament': { name: '翡翠发簪', rarity: 'rare' },
      'helmet': { name: '旅者的头盔', rarity: 'uncommon' },
      'necklace': { name: '贤者项链', rarity: 'epic' },
      'armor': { name: '硬革上衣', rarity: 'common' },
      'weapon': { name: '猎鹰短弓', rarity: 'rare' },
      'belt': { name: '编织腰带', rarity: 'common' },
      'ring': { name: '铜戒指', rarity: 'uncommon' },
      'gloves': { name: '迅捷手套', rarity: 'rare' },
      'pants': { name: '灰呢裤', rarity: 'common' },
      'boots': { name: '稳踏之靴', rarity: 'uncommon' }
    }
  };

  function setText(id, text) {
    var el = document.getElementById(id);
    if (el) el.textContent = text;
  }

  function formatPercent(v) {
    return String(v) + '%';
  }

  function applyAttributes(data) {
    setText('attr-phys-atk', data.combat.physAtk);
    setText('attr-magic-atk', data.combat.magicAtk);
    setText('attr-damage-power', data.combat.damagePower.toFixed(2));
    setText('attr-defense', data.combat.defense);
    setText('attr-resist', data.combat.resist);

    setText('attr-vitality', data.base.vitality);
    setText('attr-strength', data.base.strength);
    setText('attr-agility', data.base.agility);
    setText('attr-intelligence', data.base.intelligence);
    setText('attr-spirit', data.base.spirit);

    setText('attr-crit', formatPercent(data.tactical.crit));
    setText('attr-hit', formatPercent(data.tactical.hit));
    setText('attr-block', formatPercent(data.tactical.block));
    setText('attr-dodge', formatPercent(data.tactical.dodge));
  }

  function rarityColor(rarity) {
    switch (rarity) {
      case 'epic': return '#a58bff';
      case 'rare': return '#4aa3ff';
      case 'uncommon': return '#3bb273';
      default: return '#9aa0a6';
    }
  }

  function decorateEquipSlots(equips) {
    var slots = document.querySelectorAll('.equip-slot');
    for (var i = 0; i < slots.length; i++) {
      var slot = slots[i];
      var key = slot.getAttribute('data-slot');
      var data = equips[key];
      var label = slot.getAttribute('aria-label') || '';

      slot.title = data ? (label + '：' + data.name) : label + '：未装备';

      // 简单的中心文字标识
      var tag = document.createElement('div');
      tag.style.position = 'absolute';
      tag.style.inset = '0';
      tag.style.display = 'grid';
      tag.style.placeItems = 'center';
      tag.style.fontSize = '10px';
      tag.style.letterSpacing = '0.5px';
      tag.style.color = data ? rarityColor(data.rarity) : '#6c737a';
      tag.textContent = (label || '?').charAt(0);
      slot.appendChild(tag);

      // 稀有度边框高亮
      if (data && data.rarity) {
        var r = data.rarity;
        if (r === 'epic') slot.className += ' rarity-epic';
        else if (r === 'rare') slot.className += ' rarity-rare';
        else if (r === 'uncommon') slot.className += ' rarity-uncommon';
        else slot.className += ' rarity-common';
      } else {
        slot.className += ' rarity-common';
      }
    }
  }

  function init() {
    applyAttributes(sampleCharacter);
    decorateEquipSlots(sampleCharacter.equips);
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }
})();


